<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <main>
        <div class="row">
            男：<input type="radio" value="男" name="sex1">
            女：<input type="radio" value="女" name="sex1">
        </div>
        <div class="row">
            男：<input type="radio" value="男" name="sex2">
            女：<input type="radio" value="女" name="sex2">
        </div>
    </main>
</body>
<script>
    const inputs = [];

    // 查询row
    const divs = Array.from(document.querySelectorAll(".row"));

    // 遍历row，查找所有input，放入数组
    divs.forEach(v => {
        inputs.push(...v.querySelectorAll("input"));
    })

    function handleClick(e) {
        const target = e.currentTarget;
        // 获取父节点
        const parent = target.parentNode;
        // 在div数组中，查找父节（该方法更严谨，即使有多组也可以查找准确）
        const index = divs.findIndex(v => v == parent);
        console.log(`你点击的是${index + 1}组的：${target.value}`);
    }

    inputs.forEach(v => {
        v.addEventListener("click",handleClick);
    })

</script>
</html>